package com.yjhb.android.sbz.tool.wx;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import com.yjhb.android.sbz.Conf;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

/**
 * 创建者 zx
 * 创建时间 2020/11/19 10:53
 */
public class WxTool {
    private final String TAG = "WxTool";

    private static IWXAPI api;

    public static void regToWx(Context context) {
        api = WXAPIFactory.createWXAPI(context, Conf.WX_APP_ID, false);
        api.registerApp(Conf.WX_APP_ID);
        context.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                api.registerApp(Conf.WX_APP_ID);
            }
        }, new IntentFilter(ConstantsAPI.ACTION_REFRESH_WXAPP));
    }

    public static IWXAPI getWxApi() {
        if (api == null) {
            throw new RuntimeException("请先regToWx");
        }
        return api;
    }

}
